version: 1.3.9.{build}
configuration: Release
platform: x64

branches:
  only:
    - develop
    - master

skip_branch_with_pr: true
skip_tags: true

environment:
  matrix:
    - APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu1804
      job_name: Linux
    - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
      job_depends_on: Linux
      job_name: Windows

matrix:
  fast_finish: true

install:
  - cmd: git clone -q --branch=platform https://github.com/lintest/tools1c.git bin
  - cmd: cd bin
  - cmd: 7z x tools1c.part01.rar -p%KEY_1CV8T%
  - cmd: cd ..

  - sh: sudo add-apt-repository --remove "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main"
  - sh: sudo dpkg --add-architecture i386
  - sh: sudo apt -qq update
  - sh: sudo apt -qq -y install
      build-essential
      elfutils
      uuid-dev uuid-dev:i386
      libpcre3-dev:i386
      libx11-dev libx11-dev:i386
      libxtst-dev libxtst-dev:i386
      libxrandr-dev libxrandr-dev:i386
      libpng-dev libpng-dev:i386
      libssl-dev libssl-dev:i386
      g++-7-multilib gcc-7-multilib

  - sh: sudo update-alternatives --set gcc "/usr/bin/gcc-7"

  - cmd: git clone -q --branch=main https://github.com/libgit2/libgit2.git libgit2-1.1.0
  - cmd: cd libgit2-1.1.0
  - cmd: git checkout -b version v1.1.0
  - cmd: cd ..

  - cmd: git clone -q --branch=master https://github.com/libssh2/libssh2.git libssh2-1.9.0
  - cmd: cd libssh2-1.9.0
  - cmd: git checkout -b version libssh2-1.9.0
  - cmd: cd ..

  - git clone -q --branch=master https://github.com/opencv/opencv.git opencv-4.5.2
  - cd opencv-4.5.2
  - git checkout -b version 4.5.2
  - cd ..

  - git clone -q --branch=master --depth=1 https://github.com/lintest/RE-flex.git RE-flex
  - cd RE-flex
  - git checkout -b version v3.0.1
  - sh: ./clean.sh
  - sh: ./build.sh
  - cd ..

  - cmd: Build.OpenCV.bat
  - sh: ./Build.OpenCV.sh

  - appveyor DownloadFile https://boostorg.jfrog.io/artifactory/main/release/1.79.0/source/boost_1_79_0.tar.gz
  - tar xzf boost_1_79_0.tar.gz
  - cd boost_1_79_0
  - sh: ./bootstrap.sh
  - cmd: bootstrap.bat
  - cmd: b2.exe toolset=msvc link=static threading=multi runtime-link=static release stage --with-regex --with-date_time --with-filesystem
  - cd ..

init:
  - cmd: cmake --version
  - cmd: msbuild /version
  - cmd: echo.

build_script:
  - sh: echo "#define VERSION_FULL " ${APPVEYOR_BUILD_VERSION} > "version.h"
  - cmd: powershell -File manifest.ps1

  - sh: cd boost_1_79_0
  - sh: ./b2 cxxflags="-fPIC -std=c++17" link=static threading=multi runtime-link=static release stage --with-regex --with-date_time --with-filesystem address-model=32
  - sh: cd ..
  - mkdir build32
  - cd build32
  - sh: cmake -D CMAKE_BUILD_TYPE:STRING=RelWithDebInfo -D TARGET_PLATFORM_32:BOOL=ON ..
  - sh: cmake --build . --config RelWithDebInfo
  - cmd: cmake .. -A Win32 -DMySuffix2=32
  - cmd: cmake --build . --config Release
  - cd ..

  - sh: cd boost_1_79_0
  - sh: ./b2 cxxflags="-fPIC -std=c++17" link=static threading=multi runtime-link=static release stage --with-regex --with-date_time --with-filesystem address-model=64
  - sh: cd ..
  - mkdir build64
  - cd build64
  - sh: cmake -D CMAKE_BUILD_TYPE:STRING=RelWithDebInfo -D TARGET_PLATFORM_32:BOOL=OFF ..
  - sh: cmake --build . --config RelWithDebInfo
  - cmd: cmake .. -A x64 -DMySuffix2=64
  - cmd: cmake --build . --config Release
  - cd ..

for:
  - matrix:
      only:
        - job_name: Linux

    after_build:
      - 7z a AddIn.zip ./bin32/${APPVEYOR_PROJECT_NAME}Lin32.so
      - 7z a AddIn.zip ./bin64/${APPVEYOR_PROJECT_NAME}Lin64.so
      - 7z a AddIn.zip ./bin32/${APPVEYOR_PROJECT_NAME}Lin32.so.debug
      - 7z a AddIn.zip ./bin64/${APPVEYOR_PROJECT_NAME}Lin64.so.debug

    artifacts:
      - path: AddIn.zip

  - matrix:
      only:
        - job_name: Windows

    environment:
      KEY_1CV8T:
        secure: OolAVEKkEg1cGCpG/VK2FaM0LWrPgMR/Kn4nTLYyKR0=

    after_build:
      - 7z a keywords.zip keywords.json
      - ps: New-Item -ItemType Directory -Force -Path example/Templates/Keywords/Ext | Out-Null
      - ps: Copy-Item -Path keywords.zip -Destination example/Templates/Keywords/Ext/Template.bin
      - copy bin32\Release\%APPVEYOR_PROJECT_NAME%Win32.dll .
      - copy bin64\Release\%APPVEYOR_PROJECT_NAME%Win64.dll .
      - powershell -File appveyor.ps1
      - appveyor PushArtifact AddIn.zip
      - mkdir database
      - bin\1cv8t.exe CREATEINFOBASE File=%CD%/database
      - bin\1cv8t.exe DESIGNER /F %CD%/database /LoadConfigFromFiles %CD%/Config /UpdateDBCfg
      - bin\1cv8t.exe DESIGNER /F %CD%/database /LoadExternalDataProcessorOrReportFromFiles Example.xml %APPVEYOR_PROJECT_NAME%.epf /Out example.log
      - appveyor PushArtifact %APPVEYOR_PROJECT_NAME%.epf
      - bin\1cv8ct.exe ENTERPRISE /LRU /F %CD%/database /Execute %APPVEYOR_PROJECT_NAME%.epf /C install
      - bin\1cv8ct.exe ENTERPRISE /LRU /F %CD%/database /Execute %APPVEYOR_PROJECT_NAME%.epf /C autotest
      - ps: if (!(Test-Path success.txt)) { throw "Имеются ошибки" }

    artifacts:
      - path: ${APPVEYOR_PROJECT_NAME}.epf
      - path: AddIn.zip
      - path: Debug.zip
      - path: autotest.log
      - path: example.log

    deploy:
      - provider: GitHub
        auth_token:
          secure: v7P89NQ2I5+WGNNdhpFrZEt6OCTPf8A8VSC5rttZMXh3DJ2fTChNEjZ1Wvm3kfBt
        repository: lintest/VanessaExt
        artifact: AddIn.zip, Debug.zip, VanessaExt.epf
        draft: true
        prerelease: true
        force_update: true
        on:
          branch: master
